﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace Mbs.Threading
{
    internal struct  ReaderLock:IDisposable
    {
        private readonly ReaderWriterLockSlim Mutex;
        public ReaderLock(ReaderWriterLockSlim mutex)
        {
            Mutex = mutex;
            Mutex.EnterReadLock();
        }

        public void Dispose()
        {
            Mutex.ExitReadLock();
        }
    }

    internal struct WriterLock : IDisposable
    {
        private readonly ReaderWriterLockSlim Mutex;
        public WriterLock(ReaderWriterLockSlim mutex)
        {
            Mutex = mutex;
            Mutex.EnterWriteLock();
        }

        public void Dispose()
        {
            Mutex.ExitWriteLock();
        }
    }

    internal struct UpgradeLock : IDisposable
    {
        private readonly ReaderWriterLockSlim Mutex;
        public UpgradeLock(ReaderWriterLockSlim mutex)
        {
            Mutex = mutex;
            Mutex.EnterUpgradeableReadLock();
        }

        public void Dispose()
        {
            Mutex.ExitUpgradeableReadLock();
        }
    }
}
